//
// Created by Toosan on 2022/4/25.
//

#include "iostream"

using namespace std;

class Activity {
public:
    int task_id;
};

class BaseActivity1 : virtual public Activity {
public:
    void onCreate() {
        cout << "BaseActivity1 onCreate" << endl;
    }

    void onStart() {
        cout << "BaseActivity1 onStart" << endl;
    }
};

class BaseActivity2 : virtual public Activity {
public:
    void onCreate() {
        cout << "BaseActivity2 onCreate" << endl;
    }

    void onStart() {
        cout << "BaseActivity2 onStart" << endl;
    }
};

class BaseActivity3 {
public:
    void onCreate() {
        cout << "BaseActivity3 onCreate" << endl;
    }

    void onStart() {
        cout << "BaseActivity3 onStart" << endl;
    }
};

class MainActivity : public BaseActivity1, public BaseActivity2, public BaseActivity3 {
public:
    void onCreate() {
        cout << "MainActivity onCreate" << endl;
    }

};

/**
 * 多继承学习
 * @return
 */
int main() {
    MainActivity mainActivity;
    mainActivity.onCreate();
    // 不明确要调用哪一个父类的onStart，产生了二义性
//    mainActivity.onStart();
    // 指定调用哪一个父类的onStart()
    mainActivity.BaseActivity1::onStart();
    mainActivity.BaseActivity3::onStart();

    /**
     * 二义性，Activity中的属性，base1和base2都继续了它
     * 通过main修改，分不清是base1中继承的taskId还是是base2中继承的taskId
     */
//    mainActivity.task_id = 1;

    mainActivity.BaseActivity1::task_id = 1;
    mainActivity.BaseActivity2::task_id = 2;

    // 虚继承 [虚基类] 继承时，加上关键字：virtual  推荐这种方式来解决二义性。
    Activity activity;
    BaseActivity1 baseActivity1;
    BaseActivity2 baseActivity2;
    activity.task_id = 0;
    baseActivity1.task_id = 1;
    baseActivity2.task_id = 2;
    mainActivity.task_id = 4;

    cout << activity.task_id << endl;
    cout << mainActivity.task_id  << endl;

    return 0;
}